package com.clps.algorithm.chapter05.有效的变位词;

import java.util.HashMap;

public class demo02 {

    public static void main(String[] args) {

    }

    public boolean isAnagram(String str1,String str2){
        if(str1.length()!=str2.length()){
            return false;
        }

        HashMap<Character, Integer> counts = new HashMap<>();
        for (char ch : str1.toCharArray()) {
            counts.put(ch,counts.getOrDefault(ch,0)+1);
        }

        for (char ch : str2.toCharArray()) {
            if (counts.getOrDefault(ch, 0) == 0)
                return false;

            counts.put(ch, counts.get(ch) - 1);
        }

        return  true;
    }
}


